import req from '@/utils/request.js';
import * as URL from '@/constants/api.js';
// 购物车商品详情
export function MEMBER(id) {
  return req({
    url: URL.MEMBER,
    method: 'get',
    params: {
      id,
    },
  }).then((res) => res.data.result);
}
// 放大镜商品种类详情
export function getRelevant(id) {
  return req({
    url: URL.RELEVANT,
    params: {
      id,
      limit: 16,
    },
  })
    .then((res) => res.data.result)
    .catch((err) => Promise.reject(err.response.data));
}
// 商品详情
export function getGoodsHot(id) {
  return req({
    url: URL.GOODS_HOT,
    params: {
      id,
      limit: 3,
      type: 1,
    },
  })
    .then((res) => res.data.result)
    .catch((err) => Promise.reject(err.response.data));
}
// 购物车数据
export function getCart() {
  return req({
    url: URL.CART,
    method: 'get',
  })
    .then((res) => res.data.result)
    .catch(() =>[]);
}
// 添加购物车数量
export function addCart(params) {
  return req({
    url: URL.CART + '/' + params.skuId,
    method: 'put',
    data: {
      count: params.count,
    },
  })
    .then((res) => res.data.result)
    .catch((err) => Promise.reject(err.response.data));
}
// 删除购物车
export function deleteCart(ids) {
  return req({
    url: URL.CART,
    method: 'DELETE',
    data: {
      ids,

    },
  })
    .then((res) => res.data.result)
    .catch((err) => Promise.reject(err.response.data));
}
// 获取购物车选中状态
export function getCartChecked(id, selected) {
  return req({
    url: `${ URL.CART}/${id}`,
    method: 'put',
    data: {
      selected,
    },
  });
}
// 猜你喜欢
export function getGoodsLike(id) {
  return req({
    url: URL.CART_LIKE,
    params: {
      id,
      limit: 6,
    },
  })
    .then((res) => res.data.result)
    .catch((err) => Promise.reject(err.response.data));
}
